using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ContentOverContainer.Common;
using Roslyn.Compilers.CSharp;

namespace ContentOverContainer.Converter
{
    public static class MultConverter
    {
        public static ChangeNodeInfo ConvertMultExpression(BinaryExpressionSyntax exprSyntax, ConverterContext pConverterData)
        {           
            //check if it is our new syntax
            var parentBinExpr = exprSyntax.Parent as BinaryExpressionSyntax;
            if (parentBinExpr == null) //it's not the desired one
                return new ChangeNodeInfo(exprSyntax);
            if (parentBinExpr.OperatorToken.ToString() != "|")//it's not the desired one
                return new ChangeNodeInfo(exprSyntax);

            //R-Mult2
            if (pConverterData.MultiplicityInfo.Kind == MultiplicityKind.Any)
            {
                return new ChangeNodeInfo(Syntax.ParseExpression(string.Format("{0}.Count",exprSyntax.Right))) {OrgSyntaxNode = parentBinExpr};
            }
            //R-Mult1
            if (pConverterData.MultiplicityInfo.Kind == MultiplicityKind.Option)
            {
                return new ChangeNodeInfo(Syntax.ParseExpression(string.Format("{0} == null ? 0 : 1", exprSyntax.Right))) { OrgSyntaxNode = parentBinExpr };
            }
            return new ChangeNodeInfo(exprSyntax);
        }
    }
}
